<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\Repository;

use App\Constants\BaseConstants;
use App\Model\HotSearchModel;
use Hyperf\Di\Annotation\Inject;

class HotSearchRepository extends BaseRepository
{
    /**
     * @Inject
     * @var HotSearchModel
     */
    protected $model;

    /**
     * Notes: c端热搜词
     * Author: Bruce.z
     * DateTime: 2022/8/16 16:32
     * @return array
     */
    public function appList(): array
    {
        return $this->_searchFactor([])
            ->orderBy('sort')
            ->select(['id','name'])
            ->get()
            ->toArray();
    }

    /** c端 首页 默认热搜词
     * Notes:
     * Author: Bruce.z
     * DateTime: 2022/8/16 17:15
     * @return string
     */
    public function appOne():string
    {
        $re = $this->_searchFactor(['is_recommend'=>BaseConstants::STATUS_YES])
            ->orderBy('sort')
            ->select(['name'])
            ->first();
        return !empty($re) ? $re['name'] : '';
    }
}
